{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "from matplotlib import pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from stingray.simulator.transfer import TransferFunction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting Up Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use `Image` module from Python Imaging library to digitize 2-d plot from Uttley et al. (2014)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from PIL import Image" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "im = Image.open('2d.png')\n", "width, height = im.size" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initialize an intensity array." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "intensity = np.array([[1 for j in range(width)] for i in range(height)])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below, we retrieve each pixel and then calculate darkness value. The perceived brightness is given by:\n", "\n", "_0.2126*R + 0.7152*G + 0.0722*B_\n", "\n", "To get darkness, the formula is corrected as follows:\n", "\n", "_0.2126*(255-R) + 0.7152*(255-G) + 0.0722*(255-B)_" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for x in range(0, height):\n", " for y in range(0, width):\n", " RGB = im.getpixel((y, x))\n", " intensity[x][y] = (0.2126 * (255-RGB[0]) + 0.7152 * (255-RGB[1]) + 0.0722 * (255-RGB[2]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Invert along Y-axis to account for some conventions." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "intensity = intensity[::-1]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "np.savetxt('intensity.txt', intensity)" ] } ], "metadata": { "kernelspec": { "display_name": "py310", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 0 }